package com.example.deepseek.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ibatis.type.JdbcType;

import java.time.LocalDateTime;

/**
 * 聊天消息实体类
 * 对应数据库中的chat_message表
 */
@Data
@NoArgsConstructor
@TableName("chat_message")
public class ChatMessageEntity {

    @TableId(type = IdType.AUTO)
    private Integer id;

    private String sessionId;
    private String role;
    private String content;
    private LocalDateTime timestamp;
    private Integer deleted;

    // 文件相关字段
    @TableField(jdbcType = JdbcType.VARBINARY)
    private byte[] fileContent;

    @TableField(jdbcType = JdbcType.VARCHAR)
    private String textContent; // 添加文本内容字段

    private String filePath;
    private String fileName;

    /**
     * 基础构造函数
     */
    public ChatMessageEntity(String sessionId, String role, String content, LocalDateTime timestamp) {
        this.sessionId = sessionId;
        this.role = role;
        this.content = content;
        this.timestamp = timestamp;
        this.deleted = 0;
    }

    /**
     * 包含文件信息的构造函数
     */
    public ChatMessageEntity(String sessionId, String role, String content, LocalDateTime timestamp,
                             byte[] fileContent, String filePath, String fileName) {
        this(sessionId, role, content, timestamp);
        this.fileContent = fileContent;
        this.filePath = filePath;
        this.fileName = fileName;
    }

    /**
     * 包含文本文件内容的构造函数
     */
    public ChatMessageEntity(String sessionId, String role, String content, LocalDateTime timestamp,
                             String textContent, String filePath, String fileName) {
        this(sessionId, role, content, timestamp);
        this.textContent = textContent;
        this.filePath = filePath;
        this.fileName = fileName;
    }
}